let text = 'mon and dad and baby';
let pattern = /mon( and dad (and baby)?)?/gi;

let matches = pattern.exec(text);

console.log(matches.index);
console.log(matches.input);
console.log(matches[0]);
console.log(matches[1]);
console.log(matches[2]);
console.log(matches[3]);
// 在这个例子中，模式包含两个捕获组：最内部的匹配项" and baby"，以及外部的匹配项" and dad"
// 或" and dad and baby"。
// 0
// mon and dad and baby
// mon and dad and baby
//  and dad and baby
// and baby
// undefined

const reg = /\d{3}-\d{2}-\d{4}/gi;
console.log(reg.test('000-00-0000'));//true
console.log(reg.test('22-22-2222'));//false
console.log(reg.toString());///\d{3}-\d{2}-\d{4}/gi
console.log(reg.toLocaleString());///\d{3}-\d{2}-\d{4}/gi
console.log(typeof reg.toLocaleString());//string
console.log(typeof reg.valueOf());//object
console.log(reg.valueOf().test('0000-00-4444'));//true

